#include"ProgressBar.h"

#define length 101
#define style '#'
const char* lable = "|\\-/";

// //v1
// void ProBar(double total,double current)
// {
//     int cnt = 0;
//     char bar[length];
//     memset(bar,'\0',sizeof(bar));
//     int len = strlen(lable);

//     double rate = ((current*100.0)/total);
//     int loop_count = (int)rate;

//     while(cnt<=loop_count)
//     {
//         printf("[%-100s][%.1lf%%][%c]\r",bar,rate,lable[cnt%len]);
//         fflush(stdout);
//         bar[cnt++] = style;
//     }
// }

//v2
void ProBar(double total,double current)
{
    int cnt = 0;
    char bar[length];
    memset(bar,'\0',sizeof(bar));
    int len = strlen(lable);

    double rate = ((current*100.0)/total);
    int loop_count = (int)rate;

    while(cnt<=loop_count)
    {
        printf("[%-100s][%.1lf%%][%c]\r",bar,rate,lable[cnt%len]);
        fflush(stdout);
        bar[cnt++] = style;
    }
}